home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / DOCMANAG.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  15KB  |  447 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.12  $
  6. //
  7. // Definition of class TDocManager
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_DOCMANAG_H)
  10. #define OWL_DOCMANAG_H
  11.  
  12. #if !defined(OWL_DOCVIEW_H)
  13. # include <owl/docview.h>
  14. #endif
  15. #if !defined(OWL_APPLICAT_H)
  16. # include <owl/applicat.h>
  17. #endif
  18. #if !defined(OWL_DOCTPL_H)
  19. # include <owl/doctpl.h>
  20. #endif
  21. #if !defined(OWL_OPENSAVE_H)
  22. # include <owl/opensave.h>
  23. #endif
  24.  
  25. #if defined(BI_NAMESPACE)
  26. namespace OWL {
  27. #endif
  28.  
  29. //
  30. // Class modifier that can be used for docview classes that may be in a dll
  31. //
  32. #define _DOCVIEWCLASS _USERCLASS
  33.  
  34. //
  35. // Definitions of dmXxx document manager operational mode flags
  36. //
  37. const int dmSDI        = 0x0001;  // Does not support multiple open documents
  38. const int dmMDI        = 0x0002;  // Supports multiple open documents
  39. const int dmMenu       = 0x0004;  // Set IDs for file menu
  40. const int dmSaveEnable = 0x0010;  // Enable FileSave even if doc is unmodified
  41. const int dmNoRevert   = 0x0020;  // Disable FileRevert menu item
  42.  
  43. //
  44. // Flags which are stripped off when invoking Open/Save dialogs [See
  45. // SelectDocPath method for more information ]
  46. //
  47. const long dtProhibited = OFN_ENABLEHOOK | 
  48.                           OFN_HIDEREADONLY |
  49.                           OFN_ENABLETEMPLATE | 
  50.                           OFN_ALLOWMULTISELECT | 
  51.                           OFN_ENABLETEMPLATEHANDLE;
  52.  
  53. //
  54. // Definitions of dnXxx document/view message notifications
  55. //
  56. enum {
  57.   dnCreate,                 // New document or view has been created
  58.   dnClose,                  // Document or view has been closed
  59.   dnRename                  // Document has been renamed
  60. };
  61.  
  62. // Generic definitions/compiler options (eg. alignment) preceeding the 
  63. // definition of classes
  64. #include <services/preclass.h>
  65.  
  66. //
  67. // Class TDocManager
  68. // ~~~~~ ~~~~~~~~~~~
  69. class _OWLCLASS TDocManager : virtual public TEventHandler,
  70.                               virtual public TStreamableBase {
  71.   public:
  72.     TDocManager(int mode, TApplication* app,
  73.                 TDocTemplate*& templateHead = ::DocTemplateStaticHead);
  74.     virtual ~TDocManager();
  75.  
  76.     // Retrieve template info: count, list or descriptions
  77.     //
  78.     int                   GetTemplateCount(TDocument* ofDocType = 0, 
  79.                                            TView* ofViewType = 0);
  80.     virtual int           GetNewTemplates(TDocTemplate** tplList, int size, 
  81.                                           bool newDoc);
  82.     virtual int           GetSaveTemplates(TDocTemplate** tplList, int size,
  83.                                            TDocument& doc, bool sameDoc);
  84.     virtual int           GetViewTemplates(TDocTemplate** tplList, int size,
  85.                                            TDocument& doc);
  86.     virtual int           GetTemplateDescription(TDocTemplate** tpllist, 
  87.                                                  int tplcount, char* buff = 0, 
  88.                                                  int size = 0);
  89.  
  90.     // Create (construct & initialize) document and views
  91.     //
  92.     virtual TDocument*    CreateAnyDoc(const char far* path, long flags = 0);
  93.     TDocument*            CreateDoc(TDocTemplate* tpl, const char far* path,
  94.                                     TDocument* parent=0, long flags=0);
  95.     TDocument*            InitDoc(TDocument* doc, const char far* path, 
  96.                                   long flags);
  97.  
  98.     virtual TView*        CreateAnyView(TDocument& doc,long flags = 0);
  99.     TView*                CreateView(TDocument& doc, TDocTemplate* tpl=0);
  100.  
  101.     // Save document
  102.     //
  103.     bool                  SelectSave(TDocument& doc);
  104.     virtual TDocTemplate* SelectAnySave(TDocument& doc, bool samedoc = true);
  105.     virtual bool          FlushDoc(TDocument& doc); // Attempt to update changes
  106.  
  107.     // Find related template or document 
  108.     //
  109.     virtual TDocTemplate* MatchTemplate(const char far* path);
  110.     virtual TDocument*    GetCurrentDoc();  // Return doc with focus, else 0
  111.     TDocument*            FindDocument(const char far* path); // 0 if not found
  112.     static  bool          IsAMatch(const char far* path, const char far* fltr);
  113.  
  114.     // Accessors
  115.     //
  116.     TApplication*         GetApplication() const;
  117.     int&                  GetUntitledIndex();
  118.     TDocTemplate*         GetTemplateList() const;
  119.     TDocument::List&      GetDocList();      
  120.  
  121.     // Check Document Manager's state
  122.     //
  123.     bool                  IsFlagSet(int flag) const;
  124.     int                   GetModeFlags() const;
  125.  
  126.     // Manipulate template List [add, remove, etc]
  127.     //
  128.     TDocTemplate*         GetNextTemplate(TDocTemplate* tpl) const;
  129.     void                  RefTemplate(TDocTemplate&);    // add template ref
  130.     void                  UnRefTemplate(TDocTemplate&);  // drop template ref
  131.     void                  DeleteTemplate(TDocTemplate&); // remove from list
  132.     void                  AttachTemplate(TDocTemplate&); // append to list
  133.  
  134.     // Primary event handlers, public to allow direct invocation from app
  135.     //
  136.     virtual void          CmFileOpen();
  137.     virtual void          CmFileNew();
  138.     virtual void          CmFileClose();
  139.     virtual void          CmFileSave();
  140.     virtual void          CmFileSaveAs();
  141.     virtual void          CmFileRevert();
  142.     virtual void          CmViewCreate();
  143.  
  144.     // Overrideable document manager UI functions
  145.     //
  146.     virtual uint          PostDocError(TDocument& doc, uint sid, 
  147.                                        uint choice = MB_OK);
  148.     virtual void          PostEvent(int id, TDocument& doc); // changed doc status
  149.     virtual void          PostEvent(int id, TView& view);    // changed view status
  150.     virtual void          UpdateFileMenu(TMenu& menubar);
  151.  
  152.     // Delegated methods from TApplication
  153.     //
  154.     void                  EvPreProcessMenu(HMENU hMenu);
  155.     bool                  EvCanClose();
  156.     void                  EvWakeUp();
  157.  
  158. #if defined(OWL2_COMPAT)
  159.     TDocManager(int mode, TDocTemplate*& templateHead=::DocTemplateStaticHead);
  160. #endif
  161.  
  162.   protected:
  163.  
  164.     // Index of last untitled document
  165.     //
  166.     int                   UntitledIndex;
  167.  
  168.     // Next ID to be assigned to a view
  169.     //
  170.     uint                  NextViewId;  
  171.  
  172.     // Helper routine used by constructor(s)
  173.     //
  174.     void                  Init(int mode, TApplication* app, 
  175.                                TDocTemplate*& templateHead);
  176.  
  177.     // Overrideable document manager UI functions
  178.     //
  179.     virtual int           SelectDocType(TDocTemplate** tpllist,
  180.                                         int tplcount);
  181.     virtual int           SelectDocPath(TDocTemplate** tpllist, int tplcount,
  182.                                         char far* path, int buflen, 
  183.                                         long flags, bool save=false, TDocument* doc = NULL);
  184.     virtual int           SelectViewType(TDocTemplate** tpllist, 
  185.                                          int tplcount);
  186.  
  187.     // Overrideable method invoked just before DocManager creates a document
  188.     //
  189.     virtual bool          CreatingDoc(TDocTemplate* tpl);
  190.  
  191.   public_data:
  192.  
  193.     // List of attached documents
  194.     //
  195.     TDocument::List       DocList;      
  196.  
  197.   private:
  198.     int                   Mode;         // Mode flags: dmxxx
  199.     TDocTemplate*         TemplateList; // Chained list of doc templates
  200.     TApplication*         Application;  // Current application
  201.     TDocTemplate**        TemplateHead; // Saved pointer Template Head
  202.  
  203.     // Command enabler handlers
  204.     //
  205.     virtual void          CeFileNew(TCommandEnabler& ce);
  206.     virtual void          CeFileOpen(TCommandEnabler& ce);
  207.     virtual void          CeFileSave(TCommandEnabler& ce);
  208.     virtual void          CeFileSaveAs(TCommandEnabler& ce);
  209.     virtual void          CeFileRevert(TCommandEnabler& ce);
  210.     virtual void          CeFileClose(TCommandEnabler& ce);
  211.     virtual void          CeViewCreate(TCommandEnabler& ce);
  212.  
  213. #if defined(OWL2_COMPAT)
  214.     static bool           SelectSave(TDocTemplate* tpl, TDocument& doc);
  215.     static TView*         InitView(TView* view);
  216.     static TDocument*     InitDoc(TDocTemplate& tpl, TDocument* doc,
  217.                                   const char far* path, long flags);
  218. #endif
  219.  
  220.   DECLARE_RESPONSE_TABLE(TDocManager);
  221.   DECLARE_STREAMABLE(_OWLCLASS, TDocManager, 1);
  222.  
  223.   friend class TDocTemplate;  // access to template list, PostEvent()
  224.   friend class TDocument;     // access to Application
  225. };
  226.  
  227. //
  228. // class TDvOpenSaveData
  229. // ~~~~~ ~~~~~~~~~~~~~~~
  230. // TDvOpenSaveData encapsulates the information used to initialized
  231. // the Open or Save As dialog box by ObjectWindows' DocView manager.
  232. // Besides the typically 'OPENFILENAME' related information, it also
  233. // provides methods to retrieve the template list and template count
  234. // of the current Document Manager.
  235. //
  236. class _OWLCLASS TDvOpenSaveData : public TOpenSaveDialog::TData {
  237.   public:
  238.     TDvOpenSaveData(uint32 flags, char* filter, 
  239.                     char* initialDir, char* defExt, 
  240.                     int filterIndex, TDocTemplate **tmplList, int tmplCount);
  241.  
  242.     TDocTemplate**  GetTmplList() const;
  243.     int             GetTmplCount() const;
  244.  
  245.   protected:
  246.     int             TmplCount; // Number of Doc/View templates in 'TmplList'
  247.     int             TmplIndex; // Index of the default template.
  248.     TDocTemplate**  TmplList;  // List of Doc/View templates displayed in
  249.                                // Common Dialog during a File|Open or
  250.                                // File|SaveAs operation.
  251. };
  252.  
  253. //
  254. // class TDvOpenSaveDataOwner
  255. // ~~~~~ ~~~~~~~~~~~~~~~~~~~~
  256. // TDvOpenSaveDataOwner is a mixin class used by the DocView encapsulation
  257. // of the FileOpen and FileSave dialogs. It provides accessors to the 
  258. // template list and template count used by these dialogs. It purpose is to 
  259. // provide an  encapsulation of code shared by the TDvFileOpenDialog an 
  260. // TDvFileSaveDialog class.
  261. //
  262. class _OWLCLASS TDvOpenSaveDataOwner {
  263.   public:
  264.     TDocTemplate**    GetTmplList() const;
  265.     int               GetTmplCount() const;
  266.  
  267.   protected:
  268.     TDvOpenSaveDataOwner(TDvOpenSaveData& data);
  269.     TDvOpenSaveData&  DvData;
  270. };
  271.  
  272.  
  273. //
  274. // class TDvFileOpenDialog
  275. // ~~~~~ ~~~~~~~~~~~~~~~~~
  276. // TDvFileOpenDialog encapsulates the FileOpen dialog used by the
  277. // DocView manager. It enhances the standard ObjectWindows TFileOpenDialog 
  278. // by providing logic to update the dialog as the user switches amoung
  279. // file types.
  280. //
  281. class _OWLCLASS TDvFileOpenDialog : public TFileOpenDialog, public TDvOpenSaveDataOwner {
  282.   public:
  283.     TDvFileOpenDialog(TWindow* parent, TDvOpenSaveData& data,
  284.                       const char* title = 0);
  285.   protected:
  286.     bool              DialogFunction(uint message, TParam1, TParam2);
  287. };
  288.  
  289. //
  290. // class TDvFileSaveDialog
  291. // ~~~~~ ~~~~~~~~~~~~~~~~~
  292. // TDvFileSaveDialog encapsulates the FileSave dialog used by the
  293. // DocView manager. It enhances the standard ObjectWindows TFileSaveDialog 
  294. // by providing logic to update the dialog as the user switches amoung
  295. // file types.
  296. //
  297. class _OWLCLASS TDvFileSaveDialog : public TFileSaveDialog, public TDvOpenSaveDataOwner {
  298.   public:
  299.     TDvFileSaveDialog(TWindow* parent, TDvOpenSaveData& data,
  300.                       const char* title = 0);
  301.   protected:
  302.     bool              DialogFunction(uint message, TParam1, TParam2);
  303. };
  304.  
  305. #define EV_WM_PREPROCMENU\
  306.   {WM_OWLPREPROCMENU, 0, (TAnyDispatcher)::v_WPARAM_Dispatch,\
  307.    (TMyPMF)v_HMENU_Sig(&TMyClass::EvPreProcessMenu)}
  308.  
  309. #define EV_WM_CANCLOSE\
  310.   {WM_OWLCANCLOSE, 0, (TAnyDispatcher)::B_Dispatch,\
  311.    (TMyPMF)B_Sig(&TMyClass::EvCanClose)}
  312.  
  313. #define EV_WM_WAKEUP\
  314.   {WM_OWLWAKEUP, 0, (TAnyDispatcher)::v_Dispatch,\
  315.    (TMyPMF)v_Sig(&TMyClass::EvWakeUp)}
  316.  
  317. // Generic definitions/compiler options (eg. alignment) following the 
  318. // definition of classes
  319. #include <services/posclass.h>
  320.  
  321. #if defined(BI_NAMESPACE)
  322. } // namespace OWL
  323. #endif
  324.   
  325. //----------------------------------------------------------------------------
  326. // Inline implementations
  327. //
  328.  
  329. //
  330. // Increment the reference count of a DocView template to indicate that it's
  331. // currently in use by the DocManager.
  332. //
  333. inline void TDocManager::RefTemplate(TDocTemplate& tpl)
  334. {
  335.   ++tpl.RefCnt;
  336. }
  337.  
  338. //
  339. // Decrement the reference count of a DocView template.
  340. // NOTE: The template is deleted when the reference count reaches zero.
  341. //
  342. inline void TDocManager::UnRefTemplate(TDocTemplate& tpl)
  343. {
  344.   if (--tpl.RefCnt == 0)
  345.     delete &tpl;
  346. }
  347.  
  348. //
  349. // Returns the TApplication* object associated with this DocManager.
  350. //
  351. inline TApplication* TDocManager::GetApplication() const
  352. {
  353.   return Application;
  354. }
  355.  
  356. //
  357. // Returns true if the specified flag is currently enabled by the
  358. // DocManager or false otherwise.
  359. //
  360. inline bool TDocManager::IsFlagSet(int flag) const
  361. {
  362.   return (Mode & flag) != 0;
  363. }
  364.  
  365. //
  366. // Returns variable representing the dtXXXX flags [see DOCTPL.H for list] 
  367. // of the DocManager.
  368. //
  369. inline int TDocManager::GetModeFlags() const
  370. {
  371.   return Mode;
  372. }
  373.  
  374. //
  375. // Returns template following specified template - Pass in '0' as
  376. // parameter to get pointer to the template list.
  377. //
  378. inline TDocTemplate* TDocManager::GetNextTemplate(TDocTemplate* tpl) const
  379. {
  380.   return tpl ? tpl->GetNextTemplate() : TemplateList;
  381. }
  382.  
  383. //
  384. // Returns the index to be used by an untitled document.
  385. // NOTE: Untitled indices start at '0' and are incremented
  386. //       after a new document is created.
  387. //
  388. inline int& TDocManager::GetUntitledIndex()
  389. {
  390.   return UntitledIndex;
  391. }
  392.  
  393. //
  394. // Returns a pointer to the list of DocView templates currently
  395. // registered with the DocManager.
  396. //
  397. inline TDocTemplate* TDocManager::GetTemplateList() const
  398. {
  399.   return TemplateList;
  400. }
  401.  
  402. //
  403. // Returns a List of document currently managed by the DocManager.
  404. //
  405. inline TDocument::List& TDocManager::GetDocList()
  406. {
  407.   return DocList;
  408. }
  409.  
  410. //
  411. // Returns the list of templates displayed in the Open or Save
  412. // dialogs used by the DocManager.
  413. //
  414. inline TDocTemplate** TDvOpenSaveData::GetTmplList() const
  415. {
  416.   return TmplList;
  417. }
  418.  
  419. //
  420. // Returns the number of DocView templates currently displayed in the
  421. // Open or Save dialogs used by the DocManager.
  422. //
  423. inline int TDvOpenSaveData::GetTmplCount() const
  424. {
  425.   return TmplCount;
  426. }
  427.  
  428. //
  429. // Returns the list of templates displayed in the Open or Save
  430. // dialogs used by the DocManager.
  431. //
  432. inline TDocTemplate** TDvOpenSaveDataOwner::GetTmplList() const
  433. {
  434.   return DvData.GetTmplList();
  435. }
  436.  
  437. //
  438. // Returns the number of DocView templates currently displayed in the
  439. // Open or Save dialogs used by the DocManager.
  440. //
  441. inline int TDvOpenSaveDataOwner::GetTmplCount() const
  442. {
  443.   return DvData.GetTmplCount();
  444. }
  445.  
  446. #endif  // OWL_DOCMANAG_H
  447.